<template>
  <el-dialog :title="'费率设置'" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
      <!--  <el-form-item label="周期类型" prop="type">
        <el-radio v-model="dataForm.type" :label="1">每周（每周一自动结算）</el-radio>
        <el-radio v-model="dataForm.type" :label="2">每月（每月1号自动结算）</el-radio>
      </el-form-item>-->
      <el-form-item label="会员订单费率" prop="vipRate">
        <el-input-number style="width:100%" v-model="dataForm.vipRate" controls-position="right" :precision="2" :step="0.1"
          :max="1"></el-input-number>
      </el-form-item>
      <el-form-item label="普通费率" prop="rate" style="margin-bottom: 6px;">
        <el-input-number style="width:100%" v-model="dataForm.rate" controls-position="right" :precision="2" :step="0.1"
          :max="1"></el-input-number>
      </el-form-item>

      <el-form-item prop="facilitatorName" v-if="dataForm.facilitatorName" style="margin-bottom: 6px;">
        <span>{{dataForm.facilitatorName}}</span>
      </el-form-item>

      <el-form-item label="服务商" prop="facilitatorId">
        <el-input v-model="dataForm.facilitatorId" placeholder="输入服务商编号"></el-input>
      </el-form-item>

      <el-form-item label="邀请码" prop="invitationCode">
        <el-input v-model="dataForm.invitationCode" placeholder="输入邀请码"></el-input>
      </el-form-item>

      <el-form-item label="总店" prop="superiorSellerName">
        <el-input v-model="dataForm.superiorSellerName" placeholder="输入总店编号或者总店名称"></el-input>
      </el-form-item>

      </el-row>
      <!-- <el-form-item label="服务商费率" prop="rate">
        <el-input-number
          style="width:50%"
          v-model="dataForm.facRate"
          controls-position="right"
          :precision="2"
          :step="0.1"
          :max="1"
        ></el-input-number>
      </el-form-item>-->
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{ $t('Common.Cancel') }}</el-button>
      <el-button type="primary" @click="dataFormSubmit()">{{ $t('Common.Confirm') }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        visible: false,
        dataForm: {
          id: 0,
          type: "",
          value: "",
          vipRate: "",
          rate: "",
          facRate: "",
          createTime: "",
          facilitatorName: '',
          facilitatorId: '',
          invitationCode: '',
          superiorSellerName: '',
        },
        dataRule: {
          vipRate: [{
            required: true,
            message: "会员订单费率不能为空",
            trigger: "blur"
          }],
          rate: [{
            required: true,
            message: "普通费率不能为空",
            trigger: "blur"
          }]
        }
      };
    },
    methods: {
      init(id) {
        this.visible = true;
        this.$nextTick(() => {
          this.$refs["dataForm"].resetFields();
          this.$http({
            url: this.$http.adornUrl(`/hotel/hotelliquidationsetting/seller/` + id),
            method: "get"
          }).then(({
            data
          }) => {
            if (data && data.code === 0) {
              this.dataForm = data.hotelLiquidationSetting;
            }
          });
        });
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs["dataForm"].validate(valid => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(
                `/hotel/hotelliquidationsetting/saveOrUpdate`
              ),
              method: "post",
              data: this.$http.adornData({
                ...this.dataForm,
                facilitatorName: this.dataForm.facilitatorId
              })
            }).then(({
              data
            }) => {
              if (data && data.code === 0) {
                this.$emit("refreshDataList");
                this.$message({
                  message: "操作成功",
                  type: "success",
                  duration: 1500,
                  onClose: () => {
                    this.visible = false;
                  }
                });
              } else {
                this.$message.error(data.msg);
              }
            });
          }
        });
      }
    }
  };
</script>
